package com.leetcode.q299;

/**
 * <p> description: desc</p>
 *
 * @author tanzc
 * @date 2022/3/30
 **/
public class GetHint {
    public String getHint(String secret, String guess) {
        int bulls = 0, cows = 0;
        int[] hasLook = new int[secret.length()];
        for (int i = 0; i < guess.length(); i++) {
            if (guess.charAt(i) == secret.charAt(i)) {
                // 找到公牛
                hasLook[i] = 2;
                bulls++;
            } else {
                for (int j = 0; j < secret.length(); j++) {
                    if (j == i || hasLook[j] != 0) {
                        // 如果位置相同，则已进行过公牛判断
                        // 如果hasLook != 0说明已经是公牛或奶牛了
                        continue;
                    }
                    if (guess.charAt(i) == secret.charAt(j) && secret.charAt(j) != guess.charAt(j)) {
                        // 如果找到相等字符，且这个字符不会是公牛
                        // 找到奶牛
                        hasLook[j] = 1;
                        cows++;
                        break;
                    }
                }
            }
        }
        return new StringBuffer().append(bulls).append("A").append(cows).append("B").toString();
    }
}
